Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Windows.Forms

Public Class FrmCrHOADON_DAXUAT_SOCT_BAN

    Private Tungay, Denngay As String
    Private customerReport As ReportDocument

    Private Sub FrmCrHOADON_DAXUAT_SOCT_BAN_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        frmLoading.Show()
        Dim sqlQuery As String
        sqlQuery = "SELECT t1.ma_chungtu, t1.ngay_chungtu, t1.ma_phu, t1.thuevat as vat,"
        sqlQuery += "t3.ten_nhacungcap, t3.diachi_nhacungcap, "
        'sqlQuery += "sum(round(t2.soluongle * round(t2.dongia, 2), 0)) as thanhtien, "
        sqlQuery += "sum(t2.thanhtien)as thanhtien, "
        'sqlQuery += "round(sum(round(t2.soluongle*round(t2.dongia,2),0))*t1.thuevat/100,0) as tienvat,"
        sqlQuery += " sum(t2.thanhtien)*t1.thuevat/100 as tienvat,"
        'sqlQuery += "sum(round(t2.soluongle*round(t2.dongia,2),0))+round(sum(round(t2.soluongle*round(t2.dongia,2),0))*t1.thuevat/100,0) as tongtien"
        sqlQuery += " sum(t2.thanhtien)+sum(t2.thanhtien)*t1.thuevat/100 as  tongtien "
        sqlQuery += " FROM (tbl_dot_xuat_hoadon as t1 INNER JOIN  tbl_dot_xuat_chitiet_hoadon as t2 ON t1.ma_chungtu=t2.ma_chungtu )"
        sqlQuery += "LEFT JOIN tbl_khachhang as t3 ON t1.ma_phu=t3.ma_nhacungcap"
        sqlQuery += "  WHERE  t1.ngay_chungtu BETWEEN '" & Format(CDate(Tungay), "yyyy-MM-dd") & "' AND"
        sqlQuery += "'" & Format(CDate(Denngay), "yyyy-MM-dd") & "' AND t2.loaixuat=0 AND t2.tinhtrangxuat<>0 GROUP BY t1.ma_chungtu "
        Dim reportPath = Application.StartupPath & "\" & "crHOADON_DAXUAT_SOCT_BAN.rpt"
        customerReport = New ReportDocument()
        customerReport.Load(reportPath)
        customerReport.SetDataSource(moduleReportConfig.GetDataTable(sqlQuery))
        customerReport.SetParameterValue("TTungay", Tungay)
        customerReport.SetParameterValue("TDenngay", Denngay)
        Me.CrNXTTongHopview.ReportSource = customerReport
        frmLoading.Close()
        frmLoading.Dispose()
    End Sub


    Public Sub setTungay(ByVal s As String)
        Tungay = s
    End Sub

    Public Sub setDenngay(ByVal s As String)
        Denngay = s
    End Sub

End Class
